package com.wang.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wang.entity.TbBbsTransmit;
import com.wang.mapper.TbBbsArticleMapper;
import com.wang.mapper.TbBbsTransmitMapper;
import com.wang.response.ResultResponse;
import com.wang.service.TbBbsTransmitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


/**
 *转发
 */
@Service
public class TbBbsTransmitServiceImpl implements TbBbsTransmitService{
    @Resource
    private TbBbsTransmitMapper tbBbsTransmitMapper;
    @Autowired
    private TbBbsArticleMapper tbBbsArticleMapper;

    @Override
    public ResultResponse insertbbstransmit(TbBbsTransmit tbBbsTransmit) {
        int insert = tbBbsTransmitMapper.insert(tbBbsTransmit);
        if (insert>0){
            return ResultResponse.SUCCESS();
        }else{
            return ResultResponse.FAIED(500, "删除失败");
        }
    }

    @Override
    public ResultResponse removebbsTransmit(Integer transmitId) {
        int i = tbBbsTransmitMapper.deleteById(transmitId);
        if (i>0){
            return ResultResponse.SUCCESS();
        }else{
            return ResultResponse.FAIED(500, "删除失败");
        }
    }

    @Override
    public ResultResponse findbbsTransmit(TbBbsTransmit tbBbsTransmit) {
        QueryWrapper<TbBbsTransmit> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id",tbBbsTransmit.getUserId());
        List<TbBbsTransmit> bbsTransmits = tbBbsTransmitMapper.selectList(wrapper);
        return ResultResponse.SUCCESS(bbsTransmits);
    }

    @Override
    public ResultResponse findbbsTransmitall(TbBbsTransmit tbBbsTransmit) {
        Page<TbBbsTransmit> page = new Page<>(tbBbsTransmit.getPagenum(),tbBbsTransmit.getPagesize());
        Page<TbBbsTransmit> tbBbsTransmitPage = tbBbsTransmitMapper.selectPage(page, null);
        long total = tbBbsTransmitPage.getTotal();
        return ResultResponse.SUCCESS(tbBbsTransmitPage.getRecords(),total);
    }
}




